package com.shujia.spark

import org.apache.spark.rdd.RDD
import org.apache.spark.{SparkConf, SparkContext}

object Demo5Sample {
  def main(args: Array[String]): Unit = {

    /**
      * map  传入一行返回一行
      *
      */
    //创建sparkp配置文件对象
    val conf = new SparkConf().setAppName("map").setMaster("local")

    //上下文对象
    val sc = new SparkContext(conf)

    //读取文件构建RDD
    val studentRDD: RDD[String] = sc.textFile("spark/data/students.txt")

    /**
      * sample   懒执行
      *
      */

    val sampleRDD = studentRDD.sample(true, 0.1)

    sampleRDD.foreach(println)


  }
}
